﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsForms
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            string uid = textusername.Text;
            string pwd = textpassword.Text;

            SqlDataReader reader = DbHelper.GetReader(textusername.Text, textpassword.Text);

            if (reader.Read())
            {
                this.textusername.Text = reader["Username"].ToString();
                this.textpassword.Text = reader["Password"].ToString();

                if (uid == this.textusername.Text && pwd == this.textpassword.Text)
                {
                    MessageBox.Show("登录成功", "提示");
                    this.Hide();
                    MainForm main = new MainForm();
                    main.Show();
                }
            }
            else
            {
                MessageBox.Show("用户或密码不正确 请重新输入", "提示");
            }

        }
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            RegisterForm register = new RegisterForm();
            register.Show();
        }
    }
}
